/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// pmenu.hpp - Definition of PegMenu, PegMenu, and PegMenuButton classes.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2000 Swell Software 
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGMENU_
#define _PEGMENU_

#define PEG_MENU_CHK_WIDTH 8

#define MENU_GRAD_SLICE 32

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
enum
{
    PCI_MENU_BACK = 0,
    PCI_MENU_BACK_SEL,
    PCI_MENU_TEXT,
    PCI_MENU_TEXT_SEL,
    PCI_MENU_GRAD1,
    PCI_MENU_GRAD2,
    PCI_MENU_SEP1,
    PCI_MENU_SEP2,
    MAX_MENU_COLORS
};

/*--------------------------------------------------------------------------*/
struct PegMenuDescription
{
    const PEGCHAR *pText;
    PEGUSHORT Id;
    PEGULONG Style;
    PegMenuDescription *pSubMenu;
};

class PegMenuButton;        // forward reference

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegMenu : public PegWindow
{
    public:
        PegMenu(PegMenuDescription *pDesc, PEGBOOL Popup = FALSE);

        void CloseSiblings(PegMenuButton *NotMe);
        virtual void Draw(const PegRect &Invalid);
        PegMenuButton *FindButton(const PEGCHAR *Who);
        PegRect GetMinSize(void);
        virtual PEGINT Message(const PegMessage &Mesg);

       #ifdef PEG_KEYBOARD_SUPPORT
        virtual void MenuKeyHandler(PEGINT Key, PEGLONG Flags);
       #endif

        void SetOwner(PegThing *Who);


    protected:
        void PositionButtons(void);
};




/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegMenuBar : public PegThing
{
    public:
        PegMenuBar(PegMenuDescription *pDesc);
        virtual ~PegMenuBar();

        virtual void CloseSiblings(PegMenuButton *NotMe);
        virtual void Draw(const PegRect &Invalid);
        PegMenuButton *FindButton(const PEGCHAR *Who);
        virtual PEGBOOL InFlyoverMode(void) {return mFlyoverMode;}
        virtual PEGINT Message(const PegMessage &Mesg);
        virtual void SetFlyoverMode(PEGBOOL State) {mFlyoverMode = State;}

    protected:
       #ifdef PEG_KEYBOARD_SUPPORT
        virtual void MenuKeyHandler(PEGINT Key, PEGLONG Flags);
       #endif

        virtual void PositionButtons(void);
        virtual void SizeToParent(void);

       #ifdef PEG_PRO
        PegGradientStruct mGrad;
       #endif

        PEGBOOL mFlyoverMode;
};

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegMenuButton : public PegTextThing
{
    friend class PegMenuBar;

    public:
        PegMenuButton(PegMenuDescription *pDesc);
        virtual ~PegMenuButton();

        virtual void CloseMenu(void);
        void Disable();
        virtual void Draw(const PegRect &Invalid);
        void Enable();
        virtual PegThing *Find(PEGUSHORT Id, PEGBOOL Recursive = TRUE);
        PegMenuButton *FindButton(const PEGCHAR *Who);
        virtual PegRect GetMinSize(PEGUBYTE Type);
        PegThing *GetOwner(void) {return mpOwner;}
        PegMenu *GetSubMenu(void) {return mpSubMenu;}

        virtual PEGBOOL IsSeparator( )
        {
            if (mStyle & BF_SEPARATOR)
            {
                return TRUE;
            }
            return FALSE;
        }

        virtual PEGBOOL IsChecked(void)
        {
            if (mStyle & BF_CHECKED)
            {
                return TRUE;
            }
            return FALSE;
        }

        virtual PEGBOOL IsDotted(void)
        {
            if (mStyle & BF_DOTTED)
            {
                return TRUE;
            }
            return FALSE;
        }

        PEGBOOL IsSubVisible(void) {return mSubVisible;}
        PEGBOOL IsPointerOver(void) {return mPointerOver;}
        virtual PEGINT Message(const PegMessage &Mesg);
        virtual void SetChecked(PEGBOOL State);
        virtual void SetDotted(PEGBOOL State);
        virtual void SetOwner(PegThing *Who);
        void SetSubMenu(PegMenu *pMenu);

    protected:
        void AddSubMenu(PEGBOOL Vertical);
        void RemoveSiblingDots(void);
        void SendOwnerMessage(void);

        PegMenu *mpSubMenu;
        PegThing *mpOwner;
        PEGBOOL mSubVisible;
        PEGBOOL mPointerOver;
};

#endif

